/**
 * @(#)PeriodicSender.java
 */

/**
 *  @author Robert Denda & Didier Gutacker
 *  @version 1.0
 *  @see Periodic
 *  @see Node
 */

/**
 *
 *  original author Robert Denda, changes by Didier Gutacker
 */

class PeriodicSender extends Periodic {
  Node parent;  

  PeriodicSender( Node parent ) {
    this.parent = parent;
    timer = new Thread( parent.getNet().getThreadGroup(), this );
    timer.setPriority( Thread.MIN_PRIORITY );
    timer.start();
  } // PeriodicSender.PeriodicSender

  synchronized public void run() {
    parent.paintRequest();
    for ( ;; ) {
      if ( parent.finished() ) {
	return;
      } // if
      parent.sendMulticastPackets();
      try {
	if ( ! parent.finished() ) {
	  int speed = ((Network)parent.getNet()).getSpeed();
	  if ( speed == 1 ) {
	    wait( 4000 );		// every three seconds
	  } else if ( speed == 0 ) {
	    wait( 6000 );
	  } else {
	    wait( 3000 );
	  } // if
	} // if
      } catch( InterruptedException e ) {
      } // try
    } // for
  } // PeriodicSender.run

} // PeriodicSender
